package com.taxsearch.util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
@Component
public class LoginInterceptor implements HandlerInterceptor{

	public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3)
			throws Exception {
		System.out.println("调用了相应的视图");
	}

	public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3)
			throws Exception {
		System.out.println("调用了相应的控制器");
	}

	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object arg2) throws Exception {
		HttpSession session = request.getSession();
		//判断是否登录
		if(session.getAttribute("telphone") == null&&session.getAttribute("JSPNSRSBH")==null) {
			String url = request.getContextPath()+"/pc/toZX.do";
			response.sendRedirect(url);
			System.out.println("拦截成功");
			return false;
		}
		System.out.println("拦截验证通过");
		return true;
	}

}
